<#--<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello, World</title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #container{height:100%}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=ItCXpFeL2FCPNHuNwKHy91HDiqb3m6Tm">
        //v3.0版本的引用方式：src="http://api.map.baidu.com/api?v=3.0&ak=您的密钥"
    </script>
</head>

<body>

<div id="container"></div>
<script type="text/javascript">
    var map = new BMap.Map("container");
    // 创建地图实例
    //ar point = new BMap.Point("116.413384","39.910925");
    var point = new BMap.Point(${lng!}, ${lat!});
    // 创建点坐标
    map.centerAndZoom(point, 15);
    // 初始化地图，设置中心点坐标和地图级别
</script>
</body>
</html>-->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <title>显示当前位置—优化</title>
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #allmap {
            height: 80%;
            width: 80%;
        }
    </style>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=ItCXpFeL2FCPNHuNwKHy91HDiqb3m6Tm"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
</head>
<body>
<div id="allmap"></div>
<script type="text/javascript">
    //地图初始化
    var bm = new BMap.Map("allmap");
    bm.centerAndZoom(new BMap.Point(${lng!}, ${lat!}), 12);
    bm.enableScrollWheelZoom(true);
    bm.addControl(new BMap.NavigationControl());

    // H5 获取当前位置经纬度
    var location_lon = '', location_lat = '', myPoint; // 经度,纬度
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function (position) {
            location_lon = position.coords.longitude;
            location_lat = position.coords.latitude;
            // alert('h5经度：'+location_lon);alert('h5纬度：'+location_lat);
            myPoint = new BMap.Point(location_lon, location_lat);

            bm.centerAndZoom(myPoint, 15); // 改变地图中心点

            //添加 H5坐标 marker和label
            var markergg = new BMap.Marker(myPoint);
            bm.addOverlay(markergg); //添加GPS marker
            var labelgg = new BMap.Label("未转换的H5坐标（误差大）", {offset: new BMap.Size(20, -10)});
            markergg.setLabel(labelgg); //添加GPS label

            setTimeout(function () {
                var convertor = new BMap.Convertor();
                var pointArr = [];
                pointArr.push(myPoint);
                convertor.translate(pointArr, 1, 5, translateCallback);
            }, 1000);

            //坐标转换完之后的回调函数
            translateCallback = function (data) {
                if (data.status === 0) {
                    var marker = new BMap.Marker(data.points[0]);
                    bm.addOverlay(marker);
                    var label = new BMap.Label("转换后的百度坐标（误差小）", {offset: new BMap.Size(20, -10)});
                    marker.setLabel(label); //添加百度label
                    bm.setCenter(data.points[0]);
                }
            };
        });
    } else {
        alert("您的设备不支持定位功能");
    }

</script>
</body>
</html>
